<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- Required Stylesheets -->
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/reset.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/text.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/fonts/ptsans/stylesheet.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/fluid.css" media="screen" />

<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/mws.style.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/icons/icons.css" media="screen" />

<!-- Demo and Plugin Stylesheets -->
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/demo.css" media="screen" />
        <link rel="stylesheet" type="text/css" href="view/templates/temp1/css/timepicker.css"  />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/colorpicker/colorpicker.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/jimgareaselect/css/imgareaselect-default.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/fullcalendar/fullcalendar.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/fullcalendar/fullcalendar.print.css" media="print" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/tipsy/tipsy.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/sourcerer/Sourcerer-1.2.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/jgrowl/jquery.jgrowl.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/plugins/spinner/spinner.css" media="screen" />
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/jui/jquery.ui.css" media="screen" />

<!-- Theme Stylesheet -->
<link rel="stylesheet" type="text/css" href="view/templates/temp1/css/mws.theme.css" media="screen" />
<!--[if lt IE 9]>
<script type="text/javascript" src="view/templates/temp1/plugins/flot/excanvas.min.js"></script>
<![endif]-->

<?php 
	require_once 'model/Context/BaseContext.php';
	require_once 'model/Service/UserService.php';
	require_once 'model/ServiceResult/ServiceResult.php';
	require_once '_config/setting/SMTPConfig.php';
	require_once 'model/Util/Setting.php';
	require_once '_config/setting/global.setting.php';
	if (!file_exists('_config/setting/setting.ini'))
	{
		echo "Configuration file not found!";
	}
	else
	{
		// include class
		require_once 'plugin/Config/Config.php';
	}
	$c = new Config();
	$root =& $c->parseConfig(dirname(__FILE__).DIRECTORY_SEPARATOR.'_config/setting/setting.ini', 'inifile');
	$settingsSection =& $root->getItem("section", "delivery-collection-schedule");
	$host =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_HOST");
	$dbName =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_NAME");
	$user =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_USER");
	$pass =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_PASS");
	 
	$host = $host->getContent();
	$dbName = $dbName->getContent();
	$user = $user->getContent();
	$pass = $pass->getContent();
	
	if(isset($_POST['btn_submit']))
	{
		$c1 = new Config(); 
		$root1 =& $c1->parseConfig('_config/setting/setting.ini', 'inifile'); 
       	$settingsSection =& $root1->getItem("section", "delivery-collection-schedule");
		$host =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_HOST");
		$dbName =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_NAME");
		$user =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_USER");
		$pass =& $settingsSection->getItem("directive", "delivery_collection_schedule_MYSQL_PASS");
        			
        $host->setContent(Tool::encode($_POST['host'], "sTunnInVietnAm@2012#"));
        $dbName->setContent(Tool::encode($_POST['dbName'], "sTunnInVietnAm@2012#"));
        $user->setContent(Tool::encode($_POST['user'], "sTunnInVietnAm@2012#"));
        $pass->setContent(Tool::encode($_POST['pass'], "sTunnInVietnAm@2012#"));
        			
        $c1->writeConfig();
			
		$glb["websiteURL"] = $_POST['websiteURL'];
		$glb["settingDir"] = $_POST['settingDir'];
		$glb["layoutDir"] = $_POST['layoutDir'];
		$glb["controllerDir"] = $_POST['controllerDir'];
		$glb["contactEmail"] = $_POST['contactEmail'];

		// write configuration back 
		// read configuration data and get reference to root 
		$c0 = new Config(); 
		$root0 =& $c0->parseConfig($glb, "PHPArray"); 
					
		$options0 = array('name' => 'glb'); 
		// write configuration to file as PHP array 
		$c0->writeConfig("_config/setting/global.setting.php", "PHPArray", $options0);
				
		$smtp["host"] = Tool::encode($_POST['hostEmail'], "sTunnInVietnAm@2012#");
		$smtp["port"] = Tool::encode($_POST['port'], "sTunnInVietnAm@2012#");
		$smtp["user"] = Tool::encode($_POST['userHost'], "sTunnInVietnAm@2012#");
		$smtp["pass"] = Tool::encode($_POST['passHost'], "sTunnInVietnAm@2012#");

		// write configuration back 
		// read configuration data and get reference to root 
		$c2 = new Config(); 
		$root2 =& $c2->parseConfig($smtp, "PHPArray"); 
					
		$options2 = array('name' => 'smtp'); 
		// write configuration to file as PHP array 
		$c2->writeConfig("_config/setting/SMTPConfig.php", "PHPArray", $options2);
		//$myfile ="install.php";
		//unlink($myfile);	
		header("Location:index.php?func=dash");	
	}	
	 
?>
<div class="mws-panel grid_4" style="margin-left:27% !important;">
	<div class="mws-panel-header">
		<span class="mws-i-24 i-list">Configuration</span>
    </div>
    <div class="mws-panel-body">
    	<form class="mws-form" action="" method="post">
	    	<div class="mws-form-inline">
	           	<div class="mws-form-row">
	               	<label>Host</label>
	                <div class="mws-form-item medium">
	                	<input type="text" class="mws-textinput" name="host" value="<?php echo Tool::decode($host, 'sTunnInVietnAm@2012#')?>" />
	                 </div>
	      		</div>
	            <div class="mws-form-row">
	            	<label>Database Name</label>
	            	<div class="mws-form-item medium">
	                	<input type="text" class="mws-textinput" name="dbName" value="<?php echo Tool::decode($dbName, 'sTunnInVietnAm@2012#')?>" />
	                </div>
	        	</div>
	        	<div class="mws-form-row">
	            	<label>UserName</label>
	             	<div class="mws-form-item medium">
	                	<input type="text" class="mws-textinput" name="user" value="<?php echo Tool::decode($user, 'sTunnInVietnAm@2012#')?>" />
	              	</div>
	            </div>
	            <div class="mws-form-row">
	            	<label>Password</label>
	            	<div class="mws-form-item medium">
	            		<input type="password" class="mws-textinput" name="pass" value="<?php echo Tool::decode($pass, 'sTunnInVietnAm@2012#')?>" />
	             	</div>
	          	</div>

             	<div class="mws-form-row">
                    <label>Website URL</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="websiteURL" value="<?php echo $glb['websiteURL']?>" />
                    </div>
                </div>
            	<div class="mws-form-row">
                    <label>Setting Dir</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="settingDir" value="<?php echo $glb['settingDir']?>"/>
                    </div>
         		</div>
            	<div class="mws-form-row">
                    <label>Layout Dir</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="layoutDir" value="<?php echo $glb['layoutDir']?>"/>
                    </div>
             	</div>
            	<div class="mws-form-row">
                    <label>Controller Dir</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="controllerDir" value="<?php echo $glb['controllerDir']?>"/>
                    </div>
             	</div>
             	<div class="mws-form-row">
                    <label>Contact Email</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="contactEmail" value="<?php echo $glb['contactEmail']?>"/>
                    </div>
             	</div>
             	
             	<div class="mws-form-row">
                    <label>SMTP Host</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="hostEmail" value="<?php echo Tool::decode($smtp['host'],'sTunnInVietnAm@2012#')?>" />
                    </div>
           		</div>
           		<div class="mws-form-row">
                    <label>SMTP Port</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="port" value="<?php echo Tool::decode($smtp['port'],'sTunnInVietnAm@2012#')?>"/>
                    </div>
            	</div>
              	<div class="mws-form-row">
                    <label>UserName</label>
                    <div class="mws-form-item medium">
                    	<input type="text" class="mws-textinput" name="userHost" value="<?php echo Tool::decode($smtp['user'],'sTunnInVietnAm@2012#')?>"/>
                    </div>
             	</div>
            	<div class="mws-form-row">
                    <label>Password</label>
                    <div class="mws-form-item medium">
                    	<input type="password" class="mws-textinput" name="passHost" value="<?php echo Tool::decode($smtp['pass'],'sTunnInVietnAm@2012#')?>"/>
                    </div>
              	</div>
     		</div>
	    	<div class="mws-button-row">
	       		<input type="submit" value="Update Configuration" class="mws-button green" onclick="return confirm('Are you sure ?');" name="btn_submit" />
	       	</div>
	 	</form>
	</div>    	
</div>
